
import zhipuai

zhipuai.api_key = "41805a5412196acfdd9d63a905f9039a.Z0TWy2173NoP1ZkI"
response = zhipuai.model_api.sse_invoke(
    model="chatglm_lite",
    prompt= [{"role":"user","content":"你是一个文章标题生成器，我会给你提供一篇文章的主题和关键词，请你生成5个吸引眼球的标题，请保持标题简洁，不超过20个字。\n文章主题是“z世代多元化的职业选择”，关键词是“多元化”"}],
    temperature= 0.9,
    top_p= 0.7,
    incremental=True
)

for event in response.events():
    if event.event == "add":
        print(event.data, end="")
    elif event.event == "error" or event.event == "interrupted":
        print(event.data, end="")
    elif event.event == "finish":
        print(event.data)
        print(event.meta, end="")
    else:
        print(event.data, end="")